﻿using JiveMessenger.Interfaces;
using JiveMessenger.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace JiveMessenger.Helpers.TemplateSelector
{
   public class ChatViewModelTemplateSelector : DataTemplateSelector
    {
        public DataTemplate PrivateMessageTemplate
        {
            get;
            set;
        }
        public DataTemplate GroupChatTemplate
        {
            get;
            set;
        }

        public override DataTemplate SelectTemplate(
            object item, DependencyObject container)
        {
            if (System.ComponentModel.DesignerProperties.IsInDesignTool)
            {
                Random rnd = new Random((int)DateTime.Now.Ticks);
                if (rnd.Next(1, 10) >= 5)
                    return PrivateMessageTemplate;
                else
                    return GroupChatTemplate;


            }
            IViewModelChat itemAux = item as IViewModelChat;
            if (itemAux != null)
            {
                if (itemAux.GetType()== typeof(ViewModelGroupChat))
                    return GroupChatTemplate;
                else
                    return PrivateMessageTemplate;
            }

            return base.SelectTemplate(item, container);
        }
    }
}
